using AssemblyVerifier;
using DynamicProxies;
using DynamicProxies.Tests.InterfaceImplementation;
using DynamicProxies.Tests.Types;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Reflection;
using System.Reflection.Emit;

namespace DynamicProxies.Tests
{
	[TestClass]
	public sealed class ByRefValueTypeTests : BaseTests
	{
		// Need all the value type method call tested.
		[TestMethod]
		public void CallInt()
		{
			try
			{
				ByRefValueType simple = Proxy.Create<ByRefValueType>(this.DebugContext, this);
				var x = 3;
				simple.HookByRefInt(ref x);
				Assert.AreEqual(6, x);
			}
			catch(VerificationException exception)
			{
				Utilities.WriteVerifcationErrors(exception.Errors);
				throw;
			}
		}

		protected override sealed bool OnBeforeMethodInvocation(MethodBase target, object[] arguments)
		{
			arguments[0] = (int)arguments[0] * 2;
			return true;
		}
	}
}
